import moment from '@/common/moment.js'

export default {
	formatVal: (val, decimal = 1) => {
		if (Math.floor(val / 10000) > 0) {
			return (val / 10000).toFixed(decimal) + 'w'
		} else if (Math.floor(val / 1000) > 0) {
			return (val / 1000).toFixed(decimal) + 'k'
		}
		return val
	},
	formatDate: (time) => {
		const start = new Date(time)
		const startTime = start.getTime()
		const nowTime = new Date().getTime()
		const diff = nowTime - startTime
		const seconds = Math.floor(diff / 1000)
		const mins = Math.floor(seconds / 60)
		const hours = Math.floor(mins / 60)
		const day = Math.floor(hours / 24)
		if (start.getFullYear() < new Date().getFullYear()) {
			return moment(start).format('YYYY-MM-DD')
		} else if (start.getDate() != new Date().getDate() ||
			start.getMonth() != new Date().getMonth()) {
			return moment(start).format('MM-DD')
		} else if (hours > 0) {
			return `${hours}小时前`
		} else if (mins > 0) {
			return `${mins}分钟前`
		}
		return '1分钟内'
	},
	
}